<template>
  <van-sticky :offset-top="49">
    <article class="filter" @click="isClick">
      <span @click="filterH">点评高分</span>
      <span @click="filterG">优惠商家</span>
      <span @click="filterS">满减优惠</span>
      <span @click="filterB">品牌商家</span>
      <time><van-icon name="wap-nav" /></time>
    </article>
  </van-sticky>
  <aside class="card_container">
    <article
      class="card"
      v-for="(item, Index) in newCards"
      :key="Index"
      @click="getShopDetail(item)"
    >
      <img class="bigpic" :src="item.imgs.bigImg" alt="" />
      <img class="brand" :src="item.imgs.brandImg" alt="" />
      <div class="poilist-item-info">
        <div class="poilist-item-info1">
          <div class="poilist-item-info1couponpic">
            <img class="info1coupon-pic" :src="item.imgs.quanImg" />
          </div>
          <div class="poilist-item-info1name">
            {{ item.text.shopName }}
          </div>
        </div>
        <div class="poilist-item-info2">
          <div class="poilist-item-info2left">
            <span class="poi-info-txt score">{{ item.text.score + '分' }}</span
            ><span class="poi-info-txt">{{ item.text.yueshou }}</span
            ><span class="poi-info-txt">{{ item.text.average }}</span>
          </div>
          <div class="poilist-item-info2right"></div>
        </div>
        <div class="poilist-item-info3">
          <div class="poilist-item-info3left">
            <span class="poi-info-txt">{{ item.text.start }}</span
            ><span class="poi-info-txt no-margin-right">{{
              item.text.peisong
            }}</span>
          </div>
          <div class="poilist-item-info3right">
            <span class="poi-info-txt">{{ item.text.time }}</span
            ><span class="poi-info-txt no-margin-right">{{
              item.text.distance
            }}</span>
          </div>
        </div>
        <div class="poilist-item-info4">
          <div class="poilist-item-info4item">
            <div class="poilist-item-info4itemtxt">
              <img
                class="info4-item-txtlefticon"
                src="https://p0.meituan.net/scarlett/c9dd513df2d35c4a350c177deccdfbd64850.png"
              /><span
                class="info4-item-txt"
                style="
                  color: rgb(155, 118, 56);
                  background-color: rgb(251, 245, 232);
                "
                >{{ item.text.hot }}</span
              >
            </div>
          </div>
        </div>
        <div class="poilist-item-info5 more-icon-need">
          <div class="d_cmm-label-comp-wrap">
            <div class="d_sublabel-container d_multi-line">
              <div class="d_sublabel-block">
                <div
                  :key="index"
                  v-for="(sub, index) in item.text.youhui"
                  class="d_sublabel"
                  style="border-color: rgb(255, 198, 193)"
                >
                  <div class="d_lb-wrap">
                    <div
                      class="d_lb"
                      style="
                        color: rgb(255, 74, 38);
                        background-color: rgb(255, 255, 255);
                      "
                    >
                      {{ sub }}<span></span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <img
            class="poilist-item-info5arrow"
            src="https://p1.meituan.net/travelcube/f5943a15e313147a66cc27cbec8dba16605.png"
            @click.stop="addClass"
          />
        </div>
      </div>
    </article>
  </aside>
</template>

<script>
// 引入vuex中的状态 State 和同步修改状态的方法 Mutations
import { mapState, mapMutations } from 'vuex'
import { defineComponent } from 'vue'
// 引入api中的请求方法
import { getFoodCards } from '@/api/foodShop.js'
export default defineComponent({
  data() {
    return {
      isShow: false,
      cards: [],
      newCards: [],
      scoreFlag: true,
      discount: true,
      subFlag: true,
      brandFlag: true
    }
  },
  computed: {
    // 向vuex中的shopInfo存想要共享的数据
    ...mapState(['shopInfo'])
  },
  // 获取数据
  created() {
    getFoodCards().then((res) => {
      console.log(res.data)
      this.cards = res.data
      this.newCards = res.data
    })
  },
  methods: {
    // 调用vue中的transformInfo来修改共享数据
    ...mapMutations(['transformInfo']),
    // 过滤高分
    filterH() {
      if (this.scoreFlag) {
        this.newCards = this.cards.filter((item) => {
          return item.text.score > 4.7
        })
      } else {
        this.newCards = this.cards
      }
      this.scoreFlag = !this.scoreFlag
    },
    // 过滤优惠
    filterG() {
      if (this.discount) {
        this.newCards = this.cards.filter((item) => {
          return item.text.youhui.length > 0
        })
      } else {
        this.newCards = this.cards
      }
      this.discount = !this.discount
    },
    // 过滤满减(原生js)
    filterS() {
      if (this.subFlag) {
        this.newCards = this.cards.filter((item) => {
          console.log(item.text.youhui)
          let haveSub = false
          for (let i = 0; i < item.text.youhui.length; i++) {
            if (item.text.youhui[i].indexOf('减') !== -1) {
              haveSub = true
              break
            }
          }
          return haveSub
        })
      } else {
        this.newCards = this.cards
      }
      this.subFlag = !this.subFlag
    },
    // 过滤品牌商家
    filterB() {
      if (this.brandFlag) {
        this.newCards = this.cards.filter((item) => {
          console.log(item.imgs.quanImg)
          return item.imgs.brandImg.length > 0
        })
      } else {
        this.newCards = this.cards
      }
      this.brandFlag = !this.brandFlag
    },
    // filter 变色
    isClick(e) {
      e.target.classList.toggle('changeColor')
    },
    // 点击获取card详情页面
    getShopDetail(item) {
      this.$router.push('ShopDetail')
      this.transformInfo(item)
      console.log(this.shopInfo)
    },
    // 点击切换类名样式
    addClass(e) {
      e.target.classList.toggle('arrow-show')
      e.target.parentNode.classList.toggle('more-info5tag')
    }
  }
})
</script>

<style lang="scss" scoped>
// filter
.filter {
  height: 0.48rem;
  background: rgb(245, 245, 246);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.15rem;
  span {
    text-align: center;
    line-height: 0.28rem;
    font-size: 0.14rem;
    width: 0.78rem;
    height: 0.28rem;
    background-color: #ffffff;
    border-radius: 0.08rem;
  }
  .changeColor {
    background-color: #ffcc33;
  }
}
// 资料卡
.card_container .card {
  display: flex;
  box-sizing: border-box;
  width: 4rem;
  background-color: white;
  margin: 0 auto;
  border-radius: 0.1rem;
  border: 0.01rem solid #f2f1f0;
  padding: 0.1rem;
  position: relative;
  margin-bottom: 0.1rem;

  .bigpic {
    width: 1.08rem;
    align-self: start;
    margin-right: 0.1rem;
    border-radius: 0.06rem;
    border: 0.01rem solid #f2f1f0;
  }
  .brand {
    position: absolute;
    width: 0.34rem;
    top: 0.13rem;
    left: 0.87rem;
  }
}
// 资料卡右侧
.poilist-item-info {
  overflow: hidden;
  flex: 1;
  font-size: 14px;
  font-family: 'PingFangSC-Regular', 'Hiragino Sans GB', Arial, Helvetica,
    '宋体', sans-serif;
  .poilist-item-info1 {
    position: relative;
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    box-sizing: border-box;
    height: 0.23rem;
    .poilist-item-info1couponpic {
      -webkit-flex-shrink: 0;
      flex-shrink: 0;
      height: 0.18rem;
      margin-right: 0.04rem;
    }
  }
}
.poilist-item-info1couponpic .info1coupon-pic {
  display: block;
  height: 100%;
  -o-object-fit: cover;
  object-fit: cover;
}
.poilist-item-info1name {
  -webkit-flex: 1;
  flex: 1;
  font-weight: 700;
  font-size: 0.16rem;
  color: #222426;
  margin-right: 8px;
  line-height: 0.16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.poilist-item-info2 {
  margin-top: 0.02rem;
  position: relative;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  height: 0.14rem;
  box-sizing: border-box;
}
.poilist-item-info2left {
  -webkit-flex: 1;
  flex: 1;
  margin-right: 0.06rem;
  overflow: hidden;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-flex-wrap: nowrap;
  flex-wrap: nowrap;
}
.poilist-item-info2left .poi-info-txt.score {
  color: #ff8000;
  font-size: 0.12rem;
  font-weight: 500;
}
.poilist-item-info2left .poi-info-txt {
  font-size: 0.11rem;
  color: #858687;
  line-height: 0.14rem;
  margin-right: 0.06rem;
  white-space: nowrap;
}
.poilist-item-info3 {
  margin-top: 0.03rem;
  position: relative;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  height: 0.14rem;
  box-sizing: border-box;
}
.poilist-item-info3left {
  -webkit-flex: 1;
  flex: 1;
  margin-right: 0.06rem;
  overflow: hidden;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}
.poilist-item-info3left .poi-info-txt {
  font-size: 0.11rem;
  color: #858687;
  line-height: 0.14rem;
  margin-right: 0.06rem;
  white-space: nowrap;
}
.poilist-item-info3left .poi-info-txt.no-margin-right {
  margin-right: 2px;
}
.poilist-item-info3right {
  flex-shrink: 0;
  overflow: hidden;
  height: 0.14rem;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
}
.poilist-item-info3right .poi-info-txt {
  font-size: 0.11rem;
  color: #858687;
  line-height: 0.14rem;
  margin-left: 0.06rem;
  white-space: nowrap;
}
.poilist-item-info4 {
  margin-top: 0.04rem;
  height: 0.2rem;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  box-sizing: border-box;
}
.poilist-item-info4item {
  height: 0.2rem;
  margin-right: 4px;
  overflow: hidden;
  flex: none;
  max-width: 100%;
  border-radius: 4px;
}
.poilist-item-info4itemtxt {
  max-width: 100%;
  height: 0.2rem;
  display: flex;
  align-items: center;
  border-radius: 2px;
}
.poilist-item-info4itemtxt .info4-item-txtlefticon {
  height: 0.2rem;
}
.poilist-item-info4itemtxt .info4-item-txt {
  max-width: 100%;
  overflow: hidden;
  -webkit-flex: none;
  flex: none;
  padding: 0 2px;
  line-height: 0.2rem;
  font-size: 0.11rem;
  font-weight: 700;
}
.poilist-item-info5.more-icon-need {
  padding-right: 15px;
}
.poilist-item-info5 {
  margin-top: 0.06rem;
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  position: relative;
  height: 0.18rem;
  overflow: hidden;
}
.poilist-item-info5.more-icon-need {
  padding-right: 15px;
}
// 优惠扩展类名
.poilist-item-info5.more-info5tag {
  height: auto;
  overflow: auto;
}
.d_cmm-label-comp-wrap {
  letter-spacing: 0;
  -webkit-text-size-adjust: none;
  display: flex;
  overflow: hidden;
  box-sizing: border-box;
}
//
.d_cmm-label-comp-wrap .d_sublabel-container .d_sublabel-block {
  display: flex;
  flex-wrap: wrap;
}
.d_cmm-label-comp-wrap .d_sublabel-container .d_sublabel {
  flex: none;
  max-width: 100%;
  font-size: 2.66666667vw;
  color: #fb4e44;
  border: 0.13333333vw solid transparent;
  border-radius: 1.06666667vw;
  margin-right: 1.6vw;
  display: flex;
  align-items: center;
  margin-bottom: 0.93333333vw;
  height: 4.26666667vw;
  overflow: hidden;
}
.d_cmm-label-comp-wrap .d_sublabel-container .d_sublabel {
  box-sizing: border-box;
}
.poilist-item-info5arrow {
  position: absolute;
  right: 3px;
  top: 5px;
  height: 10px;
  transition: all 0.2s;
}
// 箭头旋转类名
.poilist-item-info5arrow.arrow-show {
  -webkit-transform: rotate(238deg);
  transform: rotate(178deg);
}
</style>
